<?php
/* 
* [***********************]
* @author: mazhenyu[houdunwangmzy@163.com]
* @Date:   2014-06-17 17:19:26
* @Last Modified time: 2014-06-19 14:41:38
*/
class TagModel extends Model{
	//指定表名
	public $table = 'tag';

	//保存标签缓存
	public $allTag;


	/**
	 * [__init 自动运行方法]
	 * @return [type] [description]
	 */
	public function __init(){
		$this->allTag = S('allTag',false,0,array('dir'=>CACHE_PATH)); 
	}

	/**
	 * [update_cache 更新缓存]
	 * @return [type] [description]
	 */
	public function update_cache(){
		$data = $this->all();
		S('allTag',$data,0,array('dir'=>CACHE_PATH));
	}

	/**
	 * [add_data 添加数据]
	 */
	public function add_data(){
		$tagName = Q('post.tagname');
		$preg = "/(\s|\r\n)+?/is";
		//正则拆分标签为数组，为了下面依次插入多条
		$tagArr = preg_split($preg, $tagName);

		foreach ($tagArr as $v) {
			if(empty($v)) continue;
			$this->add(array('tagname'=>$v));
		}
		
	}


	public function get_all(){
		return $this->all();
	}

	public function save_data(){
		$this->save();
	}
}
?>
